home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libs / readline / rltty.c < prev    next >
C/C++ Source or Header  |  1996-11-04  |  18KB  |  734 lines

  1. /* Modified by Klaus Gebhardt, October 1996 */
  2. /* rltty.c -- functions to prepare and restore the terminal for readline's
  3.    use. */
  4.  
  5. /* Copyright (C) 1992 Free Software Foundation, Inc.
  6.  
  7.    This file is part of the GNU Readline Library, a library for
  8.    reading lines of text with interactive input and history editing.
  9.  
  10.    The GNU Readline Library is free software; you can redistribute it
  11.    and/or modify it under the terms of the GNU General Public License
  12.    as published by the Free Software Foundation; either version 1, or
  13.    (at your option) any later version.
  14.  
  15.    The GNU Readline Library is distributed in the hope that it will be
  16.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  17.    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.    The GNU General Public License is often shipped with GNU software, and
  21.    is generally kept in a file called COPYING or LICENSE.  If you do not
  22.    have a copy of the license, write to the Free Software Foundation,
  23.    675 Mass Ave, Cambridge, MA 02139, USA. */
  24.  
  25. /* Modified by Klaus Gebhardt, 1996 */
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #define READLINE_LIBRARY
  32.  
  33. #if defined (HAVE_CONFIG_H)
  34. #  include "config.h"
  35. #endif
  36.  
  37. #include <sys/types.h>
  38. #include <signal.h>
  39. #include <errno.h>
  40. #include <stdio.h>
  41.  
  42. #if defined (__EMX__)
  43. #include <sys/termio.h>
  44. #endif
  45.  
  46. #if defined (HAVE_UNISTD_H)
  47. #  include <unistd.h>
  48. #endif /* HAVE_UNISTD_H */
  49.  
  50. #include "rldefs.h"
  51. #include "readline.h"
  52.  
  53. #if !defined (errno)
  54. extern int errno;
  55. #endif /* !errno */
  56.  
  57. extern int readline_echoing_p;
  58. extern int _rl_eof_char;
  59.  
  60. #if defined (__GO32__)
  61. #  include <sys/pc.h>
  62. #  undef HANDLE_SIGNALS
  63. #endif /* __GO32__ */
  64.  
  65. /* **************************************************************** */
  66. /*                                    */
  67. /*               Signal Management                */
  68. /*                                    */
  69. /* **************************************************************** */
  70.  
  71. #if defined (HAVE_POSIX_SIGNALS)
  72. static sigset_t sigint_set, sigint_oset;
  73. #else /* !HAVE_POSIX_SIGNALS */
  74. #  if defined (HAVE_BSD_SIGNALS)
  75. static int sigint_oldmask;
  76. #  endif /* HAVE_BSD_SIGNALS */
  77. #endif /* !HAVE_POSIX_SIGNALS */
  78.  
  79. static int sigint_blocked = 0;
  80.  
  81. /* Cause SIGINT to not be delivered until the corresponding call to
  82.    release_sigint(). */
  83. static void
  84. block_sigint ()
  85. {
  86.   if (sigint_blocked)
  87.     return;
  88.  
  89. #if defined (__EMX__)
  90.   sigemptyset (&sigint_set);
  91.   sigemptyset (&sigint_oset);
  92.   sigaddset (&sigint_set, SIGINT);
  93.   sigaddset (&sigint_set, SIGBREAK);
  94.   sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset);
  95. #else
  96. #if defined (HAVE_POSIX_SIGNALS)
  97.   sigemptyset (&sigint_set);
  98.   sigemptyset (&sigint_oset);
  99.   sigaddset (&sigint_set, SIGINT);
  100.   sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset);
  101. #else /* !HAVE_POSIX_SIGNALS */
  102. #  if defined (HAVE_BSD_SIGNALS)
  103.   sigint_oldmask = sigblock (sigmask (SIGINT));
  104. #  else /* !HAVE_BSD_SIGNALS */
  105. #    if defined (HAVE_USG_SIGHOLD)
  106.   sighold (SIGINT);
  107. #    endif /* HAVE_USG_SIGHOLD */
  108. #  endif /* !HAVE_BSD_SIGNALS */
  109. #endif /* !HAVE_POSIX_SIGNALS */
  110. #endif
  111.  
  112.   sigint_blocked = 1;
  113. }
  114.  
  115. /* Allow SIGINT to be delivered. */
  116. static void
  117. release_sigint ()
  118. {
  119.   if (!sigint_blocked)
  120.     return;
  121.  
  122. #if defined (__EMX__)
  123.   sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL);
  124. #else
  125. #if defined (HAVE_POSIX_SIGNALS)
  126.   sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL);
  127. #else
  128. #  if defined (HAVE_BSD_SIGNALS)
  129.   sigsetmask (sigint_oldmask);
  130. #  else /* !HAVE_BSD_SIGNALS */
  131. #    if defined (HAVE_USG_SIGHOLD)
  132.   sigrelse (SIGINT);
  133. #    endif /* HAVE_USG_SIGHOLD */
  134. #  endif /* !HAVE_BSD_SIGNALS */
  135. #endif /* !HAVE_POSIX_SIGNALS */
  136. #endif
  137.  
  138.   sigint_blocked = 0;
  139. }
  140.  
  141. /* **************************************************************** */
  142. /*                                    */
  143. /*         Controlling the Meta Key and Keypad            */
  144. /*                                    */
  145. /* **************************************************************** */
  146.  
  147. extern int term_has_meta;
  148. extern char *term_mm;
  149. extern char *term_mo;
  150.  
  151. extern char *term_ks;
  152. extern char *term_ke;
  153.  
  154. static int
  155. outchar (c)
  156.      int c;
  157. {
  158.   return putc (c, rl_outstream);
  159. }
  160.  
  161. /* Turn on/off the meta key depending on ON. */
  162. static void
  163. control_meta_key (on)
  164.      int on;
  165. {
  166.   if (term_has_meta)
  167.     {
  168.       if (on && term_mm)
  169.     tputs (term_mm, 1, outchar);
  170.       else if (!on && term_mo)
  171.     tputs (term_mo, 1, outchar);
  172.     }
  173. }
  174.  
  175. #if 0
  176. static void
  177. control_keypad (on)
  178.      int on;
  179. {
  180.   if (on && term_ks)
  181.     tputs (term_ks, 1, outchar);
  182.   else if (!on && term_ke)
  183.     tputs (term_ke, 1, outchar);
  184. }
  185. #endif
  186.  
  187. /* **************************************************************** */
  188. /*                                    */
  189. /*              Saving and Restoring the TTY                */
  190. /*                                    */
  191. /* **************************************************************** */
  192.  
  193. /* Non-zero means that the terminal is in a prepped state. */
  194. static int terminal_prepped = 0;
  195.  
  196. /* If non-zero, means that this process has called tcflow(fd, TCOOFF)
  197.    and output is suspended. */
  198. #if defined (__ksr1__)
  199. static int ksrflow = 0;
  200. #endif
  201. #if defined (NEW_TTY_DRIVER)
  202.  
  203. /* Values for the `flags' field of a struct bsdtty.  This tells which
  204.    elements of the struct bsdtty have been fetched from the system and
  205.    are valid. */
  206. #define SGTTY_SET    0x01
  207. #define LFLAG_SET    0x02
  208. #define TCHARS_SET    0x04
  209. #define LTCHARS_SET    0x08
  210.  
  211. struct bsdtty {
  212.   struct sgttyb sgttyb;    /* Basic BSD tty driver information. */
  213.   int lflag;        /* Local mode flags, like LPASS8. */
  214. #if defined (TIOCGETC)
  215.   struct tchars tchars;    /* Terminal special characters, including ^S and ^Q. */
  216. #endif
  217. #if defined (TIOCGLTC)
  218.   struct ltchars ltchars; /* 4.2 BSD editing characters */
  219. #endif
  220.   int flags;        /* Bitmap saying which parts of the struct are valid. */
  221. };
  222.  
  223. #define TIOTYPE struct bsdtty
  224.  
  225. static TIOTYPE otio;
  226.  
  227. static int
  228. get_tty_settings (tty, tiop)
  229.      int tty;
  230.      TIOTYPE *tiop;
  231. {
  232. #if !defined (SHELL) && defined (TIOCGWINSZ)
  233.   struct winsize w;
  234.  
  235.   if (ioctl (tty, TIOCGWINSZ, &w) == 0)
  236.       (void) ioctl (tty, TIOCSWINSZ, &w);
  237. #endif
  238.  
  239.   tiop->flags = tiop->lflag = 0;
  240.  
  241.   ioctl (tty, TIOCGETP, &(tiop->sgttyb));
  242.   tiop->flags |= SGTTY_SET;
  243.  
  244. #if defined (TIOCLGET)
  245.   ioctl (tty, TIOCLGET, &(tiop->lflag));
  246.   tiop->flags |= LFLAG_SET;
  247. #endif
  248.  
  249. #if defined (TIOCGETC)
  250.   ioctl (tty, TIOCGETC, &(tiop->tchars));
  251.   tiop->flags |= TCHARS_SET;
  252. #endif
  253.  
  254. #if defined (TIOCGLTC)
  255.   ioctl (tty, TIOCGLTC, &(tiop->ltchars));
  256.   tiop->flags |= LTCHARS_SET;
  257. #endif
  258.  
  259.   return 0;
  260. }
  261.  
  262. set_tty_settings (tty, tiop)
  263.      int tty;
  264.      TIOTYPE *tiop;
  265. {
  266.   if (tiop->flags & SGTTY_SET)
  267.     {
  268.       ioctl (tty, TIOCSETN, &(tiop->sgttyb));
  269.       tiop->flags &= ~SGTTY_SET;
  270.     }
  271.   readline_echoing_p = 1;
  272.  
  273. #if defined (TIOCLSET)
  274.   if (tiop->flags & LFLAG_SET)
  275.     {
  276.       ioctl (tty, TIOCLSET, &(tiop->lflag));
  277.       tiop->flags &= ~LFLAG_SET;
  278.     }
  279. #endif
  280.  
  281. #if defined (TIOCSETC)
  282.   if (tiop->flags & TCHARS_SET)
  283.     {
  284.       ioctl (tty, TIOCSETC, &(tiop->tchars));
  285.       tiop->flags &= ~TCHARS_SET;
  286.     }
  287. #endif
  288.  
  289. #if defined (TIOCSLTC)
  290.   if (tiop->flags & LTCHARS_SET)
  291.     {
  292.       ioctl (tty, TIOCSLTC, &(tiop->ltchars));
  293.       tiop->flags &= ~LTCHARS_SET;
  294.     }
  295. #endif
  296.  
  297.   return 0;
  298. }
  299.  
  300. static void
  301. prepare_terminal_settings (meta_flag, otio, tiop)
  302.      int meta_flag;
  303.      TIOTYPE otio, *tiop;
  304. {
  305. #if !defined (__GO32__)
  306.   readline_echoing_p = (otio.sgttyb.sg_flags & ECHO);
  307.  
  308.   /* Copy the original settings to the structure we're going to use for
  309.      our settings. */
  310.   tiop->sgttyb = otio.sgttyb;
  311.   tiop->lflag = otio.lflag;
  312. #if defined (TIOCGETC)
  313.   tiop->tchars = otio.tchars;
  314. #endif
  315. #if defined (TIOCGLTC)
  316.   tiop->ltchars = otio.ltchars;
  317. #endif
  318.   tiop->flags = otio.flags;
  319.  
  320.   /* First, the basic settings to put us into character-at-a-time, no-echo
  321.      input mode. */
  322.   tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD);
  323.   tiop->sgttyb.sg_flags |= CBREAK;
  324.  
  325.   /* If this terminal doesn't care how the 8th bit is used, then we can
  326.      use it for the meta-key.  If only one of even or odd parity is
  327.      specified, then the terminal is using parity, and we cannot. */
  328. #if !defined (ANYP)
  329. #  define ANYP (EVENP | ODDP)
  330. #endif
  331.   if (((otio.sgttyb.sg_flags & ANYP) == ANYP) ||
  332.       ((otio.sgttyb.sg_flags & ANYP) == 0))
  333.     {
  334.       tiop->sgttyb.sg_flags |= ANYP;
  335.  
  336.       /* Hack on local mode flags if we can. */
  337. #if defined (TIOCLGET)
  338. #  if defined (LPASS8)
  339.       tiop->lflag |= LPASS8;
  340. #  endif /* LPASS8 */
  341. #endif /* TIOCLGET */
  342.     }
  343.  
  344. #if defined (TIOCGETC)
  345. #  if defined (USE_XON_XOFF)
  346.   /* Get rid of terminal output start and stop characters. */
  347.   tiop->tchars.t_stopc = -1; /* C-s */
  348.   tiop->tchars.t_startc = -1; /* C-q */
  349.  
  350.   /* If there is an XON character, bind it to restart the output. */
  351.   if (otio.tchars.t_startc != -1)
  352.     rl_bind_key (otio.tchars.t_startc, rl_restart_output);
  353. #  endif /* USE_XON_XOFF */
  354.  
  355.   /* If there is an EOF char, bind _rl_eof_char to it. */
  356.   if (otio.tchars.t_eofc != -1)
  357.     _rl_eof_char = otio.tchars.t_eofc;
  358.  
  359. #  if defined (NO_KILL_INTR)
  360.   /* Get rid of terminal-generated SIGQUIT and SIGINT. */
  361.   tiop->tchars.t_quitc = -1; /* C-\ */
  362.   tiop->tchars.t_intrc = -1; /* C-c */
  363. #  endif /* NO_KILL_INTR */
  364. #endif /* TIOCGETC */
  365.  
  366. #if defined (TIOCGLTC)
  367.   /* Make the interrupt keys go away.  Just enough to make people happy. */
  368.   tiop->ltchars.t_dsuspc = -1;    /* C-y */
  369.   tiop->ltchars.t_lnextc = -1;    /* C-v */
  370. #endif /* TIOCGLTC */
  371. #endif /* !__GO32__ */
  372. }
  373.  
  374. #else  /* !defined (NEW_TTY_DRIVER) */
  375.  
  376. #if !defined (VMIN)
  377. #  define VMIN VEOF
  378. #endif
  379.  
  380. #if !defined (VTIME)
  381. #  define VTIME VEOL
  382. #endif
  383.  
  384. #if defined (TERMIOS_TTY_DRIVER)
  385. #  define TIOTYPE struct termios
  386. #  define DRAIN_OUTPUT(fd)    tcdrain (fd)
  387. #  define GETATTR(tty, tiop)    (tcgetattr (tty, tiop))
  388. #  define SETATTR(tty, tiop)    (tcsetattr (tty, TCSANOW, tiop))
  389. #else
  390. #  define TIOTYPE struct termio
  391. #  define DRAIN_OUTPUT(fd)
  392. #  define GETATTR(tty, tiop)    (ioctl (tty, TCGETA, tiop))
  393. #  define SETATTR(tty, tiop)    (ioctl (tty, TCSETA, tiop))
  394. #endif /* !TERMIOS_TTY_DRIVER */
  395.  
  396. static TIOTYPE otio;
  397.  
  398. #if defined (FLUSHO)
  399. #  define OUTPUT_BEING_FLUSHED(tp)  (tp->c_lflag & FLUSHO)
  400. #else
  401. #  define OUTPUT_BEING_FLUSHED(tp)  0
  402. #endif
  403.  
  404. static int
  405. get_tty_settings (tty, tiop)
  406.      int tty;
  407.      TIOTYPE *tiop;
  408. {
  409.   int ioctl_ret;
  410. #if !defined (SHELL) && defined (TIOCGWINSZ)
  411.   struct winsize w;
  412.  
  413.   if (ioctl (tty, TIOCGWINSZ, &w) == 0)
  414.       (void) ioctl (tty, TIOCSWINSZ, &w);
  415. #endif
  416.  
  417.   /* Keep looping if output is being flushed after a ^O (or whatever
  418.      the flush character is). */
  419.   while ((ioctl_ret = GETATTR (tty, tiop)) < 0 || OUTPUT_BEING_FLUSHED (tiop))
  420.     {
  421.       if (ioctl_ret < 0 && errno != EINTR)
  422.     return -1;
  423.       if (OUTPUT_BEING_FLUSHED (tiop))
  424.         continue;
  425.       errno = 0;
  426.     }
  427.   return 0;
  428. }
  429.  
  430. static int
  431. set_tty_settings (tty, tiop)
  432.      int tty;
  433.      TIOTYPE *tiop;
  434. {
  435.   while (SETATTR (tty, tiop) < 0)
  436.     {
  437.       if (errno != EINTR)
  438.     return -1;
  439.       errno = 0;
  440.     }
  441.  
  442. #if 0
  443.  
  444. #if defined (TERMIOS_TTY_DRIVER)
  445. #  if defined (__ksr1__)
  446.   if (ksrflow)
  447.     {
  448.       ksrflow = 0;
  449.       tcflow (tty, TCOON);
  450.     }
  451. #  else /* !ksr1 */
  452.   tcflow (tty, TCOON);        /* Simulate a ^Q. */
  453. #  endif /* !ksr1 */
  454. #else
  455.   ioctl (tty, TCXONC, 1);    /* Simulate a ^Q. */
  456. #endif /* !TERMIOS_TTY_DRIVER */
  457.  
  458. #endif
  459.  
  460.   return 0;
  461. }
  462.  
  463. static void
  464. prepare_terminal_settings (meta_flag, otio, tiop)
  465.      int meta_flag;
  466.      TIOTYPE otio, *tiop;
  467. {
  468.   readline_echoing_p = (otio.c_lflag & ECHO);
  469.  
  470. #if defined (__EMX__)
  471.   tiop->c_lflag &= ~IDEFAULT;
  472. #endif /* __EMX__ */
  473.   tiop->c_lflag &= ~(ICANON | ECHO);
  474.  
  475.   if ((unsigned char) otio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
  476.     _rl_eof_char = otio.c_cc[VEOF];
  477.  
  478. #if defined (USE_XON_XOFF)
  479. #if defined (IXANY)
  480.   tiop->c_iflag &= ~(IXON | IXOFF | IXANY);
  481. #else
  482.   /* `strict' Posix systems do not define IXANY. */
  483.   tiop->c_iflag &= ~(IXON | IXOFF);
  484. #endif /* IXANY */
  485. #endif /* USE_XON_XOFF */
  486.  
  487.   /* Only turn this off if we are using all 8 bits. */
  488.   if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag)
  489.     tiop->c_iflag &= ~(ISTRIP | INPCK);
  490.  
  491.   /* Make sure we differentiate between CR and NL on input. */
  492.   tiop->c_iflag &= ~(ICRNL | INLCR);
  493.  
  494. #if !defined (HANDLE_SIGNALS)
  495.   tiop->c_lflag &= ~ISIG;
  496. #else
  497.   tiop->c_lflag |= ISIG;
  498. #endif
  499.  
  500.   tiop->c_cc[VMIN] = 1;
  501.   tiop->c_cc[VTIME] = 0;
  502.  
  503. #if defined (FLUSHO)
  504.   if (OUTPUT_BEING_FLUSHED (tiop))
  505.     {
  506.       tiop->c_lflag &= ~FLUSHO;
  507.       otio.c_lflag &= ~FLUSHO;
  508.     }
  509. #endif
  510.  
  511.   /* Turn off characters that we need on Posix systems with job control,
  512.      just to be sure.  This includes ^Y and ^V.  This should not really
  513.      be necessary.  */
  514. #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)
  515.  
  516. #if defined (VLNEXT)
  517.   tiop->c_cc[VLNEXT] = _POSIX_VDISABLE;
  518. #endif
  519.  
  520. #if defined (VDSUSP)
  521.   tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;
  522. #endif
  523.  
  524. #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
  525. }
  526. #endif  /* NEW_TTY_DRIVER */
  527.  
  528. /* Put the terminal in CBREAK mode so that we can detect key presses. */
  529. void
  530. rl_prep_terminal (meta_flag)
  531.      int meta_flag;
  532. {
  533. #if !defined (__GO32__)
  534.   int tty = fileno (rl_instream);
  535.   TIOTYPE tio;
  536.  
  537.   if (terminal_prepped)
  538.     return;
  539.  
  540.   /* Try to keep this function from being INTerrupted. */
  541.   block_sigint ();
  542.  
  543.   if (get_tty_settings (tty, &tio) < 0)
  544.     {
  545.       release_sigint ();
  546.       return;
  547.     }
  548.  
  549.   otio = tio;
  550.  
  551.   prepare_terminal_settings (meta_flag, otio, &tio);
  552.  
  553.   if (set_tty_settings (tty, &tio) < 0)
  554.     {
  555.       release_sigint ();
  556.       return;
  557.     }
  558.  
  559.   control_meta_key (1);
  560. #if 0
  561.   control_keypad (1);
  562. #endif
  563.   fflush (rl_outstream);
  564.   terminal_prepped = 1;
  565.  
  566.   release_sigint ();
  567. #endif /* !__GO32__ */
  568. }
  569.  
  570. /* Restore the terminal's normal settings and modes. */
  571. void
  572. rl_deprep_terminal ()
  573. {
  574. #if !defined (__GO32__)
  575.   int tty = fileno (rl_instream);
  576.  
  577.   if (!terminal_prepped)
  578.     return;
  579.  
  580.   /* Try to keep this function from being INTerrupted. */
  581.   block_sigint ();
  582.  
  583.   control_meta_key (0);
  584. #if 0
  585.   control_keypad (0);
  586. #endif
  587.   fflush (rl_outstream);
  588.  
  589.   if (set_tty_settings (tty, &otio) < 0)
  590.     {
  591.       release_sigint ();
  592.       return;
  593.     }
  594.  
  595.   terminal_prepped = 0;
  596.  
  597.   release_sigint ();
  598. #endif /* !__GO32__ */
  599. }
  600.  
  601. /* **************************************************************** */
  602. /*                                    */
  603. /*            Bogus Flow Control                  */
  604. /*                                    */
  605. /* **************************************************************** */
  606.  
  607. rl_restart_output (count, key)
  608.      int count, key;
  609. {
  610.   int fildes = fileno (rl_outstream);
  611. #if defined (TIOCSTART)
  612. #if defined (apollo)
  613.   ioctl (&fildes, TIOCSTART, 0);
  614. #else
  615.   ioctl (fildes, TIOCSTART, 0);
  616. #endif /* apollo */
  617.  
  618. #else /* !TIOCSTART */
  619. #  if defined (TERMIOS_TTY_DRIVER)
  620. #    if defined (__ksr1__)
  621.   if (ksrflow)
  622.     {
  623.       ksrflow = 0;
  624.       tcflow (fildes, TCOON);
  625.     }
  626. #    else /* !ksr1 */
  627.   tcflow (fildes, TCOON);        /* Simulate a ^Q. */
  628. #    endif /* !ksr1 */
  629. #  else /* !TERMIOS_TTY_DRIVER */
  630. #    if defined (TCXONC)
  631.   ioctl (fildes, TCXONC, TCOON);
  632. #    endif /* TCXONC */
  633. #  endif /* !TERMIOS_TTY_DRIVER */
  634. #endif /* !TIOCSTART */
  635.  
  636.   return 0;
  637. }
  638.  
  639. rl_stop_output (count, key)
  640.      int count, key;
  641. {
  642.   int fildes = fileno (rl_instream);
  643.  
  644. #if defined (TIOCSTOP)
  645. # if defined (apollo)
  646.   ioctl (&fildes, TIOCSTOP, 0);
  647. # else
  648.   ioctl (fildes, TIOCSTOP, 0);
  649. # endif /* apollo */
  650. #else /* !TIOCSTOP */
  651. # if defined (TERMIOS_TTY_DRIVER)
  652. #  if defined (__ksr1__)
  653.   ksrflow = 1;
  654. #  endif /* ksr1 */
  655.   tcflow (fildes, TCOOFF);
  656. # else
  657. #   if defined (TCXONC)
  658.   ioctl (fildes, TCXONC, TCOON);
  659. #   endif /* TCXONC */
  660. # endif /* !TERMIOS_TTY_DRIVER */
  661. #endif /* !TIOCSTOP */
  662.  
  663.   return 0;
  664. }
  665.  
  666. /* **************************************************************** */
  667. /*                                    */
  668. /*            Default Key Bindings                */
  669. /*                                    */
  670. /* **************************************************************** */
  671. void
  672. rltty_set_default_bindings (kmap)
  673.      Keymap kmap;
  674. {
  675.   TIOTYPE ttybuff;
  676.   int tty = fileno (rl_instream);
  677.  
  678. #if defined (NEW_TTY_DRIVER)
  679.  
  680. #define SET_SPECIAL(sc, func) \
  681.   do \
  682.     { \
  683.       int ic; \
  684.       ic = sc; \
  685.       if (ic != -1 && kmap[ic].type == ISFUNC) \
  686.     kmap[ic].function = func; \
  687.     } \
  688.   while (0)
  689.  
  690.   if (get_tty_settings (tty, &ttybuff) == 0)
  691.     {
  692.       if (ttybuff.flags & SGTTY_SET)
  693.     {
  694.       SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout);
  695.       SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard);
  696.     }
  697.  
  698. #  if defined (TIOCGLTC)
  699.       if (ttybuff.flags & LTCHARS_SET)
  700.     {
  701.       SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout);
  702.       SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert);
  703.     }
  704. #  endif /* TIOCGLTC */
  705.     }
  706.  
  707. #else /* !NEW_TTY_DRIVER */
  708.  
  709. #define SET_SPECIAL(sc, func) \
  710.   do \
  711.     { \
  712.       unsigned char uc; \
  713.       uc = ttybuff.c_cc[sc]; \
  714.       if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \
  715.     kmap[uc].function = func; \
  716.     } \
  717.   while (0)
  718.  
  719.   if (get_tty_settings (tty, &ttybuff) == 0)
  720.     {
  721.       SET_SPECIAL (VERASE, rl_rubout);
  722.       SET_SPECIAL (VKILL, rl_unix_line_discard);
  723.  
  724. #  if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
  725.       SET_SPECIAL (VLNEXT, rl_quoted_insert);
  726. #  endif /* VLNEXT && TERMIOS_TTY_DRIVER */
  727.  
  728. #  if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
  729.       SET_SPECIAL (VWERASE, rl_unix_word_rubout);
  730. #  endif /* VWERASE && TERMIOS_TTY_DRIVER */
  731.     }
  732. #endif /* !NEW_TTY_DRIVER */
  733. }
  734.